package com.zhuxulin.android.test.adapter;

import java.util.List;

import com.zhuxulin.android.test.R;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class MainAdapter extends BaseAdapter {

	private Context context = null;;
	private List<String> data = null;

	public MainAdapter(Context context, List<String> data) {
		this.context = context;
		this.data = data;
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View c, ViewGroup parent) {
		ViewHolder holder = null;
		if (c == null) {
			c = LayoutInflater.from(context).inflate(R.layout.i_f_main, null);
			holder = new ViewHolder();
			holder.title = (TextView) c.findViewById(R.id.title);
			holder.action = (TextView) c.findViewById(R.id.action);
			holder.time = (TextView) c.findViewById(R.id.time);
			c.setTag(holder);
		} else {
			holder = (ViewHolder) c.getTag();
		}
		String s = data.get(position);
		holder.title.setText(s.substring(s.lastIndexOf('.') + 1, s.length()));
		holder.action.setText(s);
		return c;
	}

	static class ViewHolder {
		TextView title;
		TextView action;
		TextView time;
	}
}
